package controller.environment.ground;

import java.awt.Color;
import java.util.ArrayList;

import controller.algorithms.AlgorithmManager;
import controller.environment.GroundManager;
import utilities.clock.Clock;
import utilities.clock.ClockListener;
import view.completeView.groundView.GroundListener;

public abstract class Ground implements ClockListener {
	private Clock m_clock;
	protected GroundManager m_groundManager;
	protected int m_posX;
	protected int m_posY;
	protected double m_amountWork;
	protected ArrayList<GroundListener> listeners;
	
	public Ground(GroundManager ground_manager, int pos_x, int pos_y){
		m_groundManager = ground_manager;
		setPosX(pos_x);
		setPosY(pos_y);
		m_clock = Clock.getClock();
		m_clock.addClockListener(this);
	}

	public abstract void evolve();
	
	public int getPosX() {
		return m_posX;
	}

	public void setPosX(int m_posX) {
		this.m_posX = m_posX;
	}

	public int getPosY() {
		return m_posY;
	}

	public void setPosY(int m_posY) {
		this.m_posY = m_posY;
	}
	
	public void acts(){
		actsParticular();
		AlgorithmManager.getInstance().getAlgorithm().nextStepGround(this);
	}
	
	public abstract void actsParticular();
	
	public void setClock(Clock this_clock){
		m_clock = this_clock;
	}
	
	public double getAmountWork(){
		return m_amountWork;
	}
	
	public void setAmountWork(double amount_work){
		m_amountWork = amount_work;
	}
	
	public boolean diminishWork(double work_in_less){
		m_amountWork -= work_in_less;
		if(m_amountWork<0.0){
			this.evolve();
			return false;
		}
		return true;
	}
	
	public abstract Color getColor();
}
